package dp;
import java.io.*;
import java.util.*;
public class _08_kama_46_01背包_滚动数组 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static int N = 5010;
	static int n,m;
	static int weight[] = new int[N];
	static int value[] = new int[N];
	static int dp[] = new int[N];
	static StringTokenizer st;
	public static void main(String[] args) throws IOException {
		st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			weight[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			value[i] = Integer.parseInt(st.nextToken());
		}
		for(int i = 1; i <= n; i++) { // 物品
			for(int j = m; j >= weight[i]; j--) { // 容积
				dp[j] = Math.max(dp[j], dp[j-weight[i]] + value[i]);
			}
		}

		System.out.println(dp[m]);
	}
}
